import datetime
from after.models import ReturnDevice


def getStrTime(strf="%Y-%m-%d"):
    time = datetime.datetime.now()
    return time.strftime(strf)


def getTag(tag, type):
    """

    :param tag: 状态好
    :param type: 0-审核状态 1-发货状态 2-退货换 3-公司 4-设备
    :return:
    """
    review_status = {
        0: "未审核",
        1: "审核通过",
        2: "审核未通过"
    }

    delivery_status = {
        0: "未发货",
        1: "已发货",
    }
    return_type = {
        0: "退货",
        1: "换货"
    }
    bs = {
        0: "巨石",
        1: "全电"
    }

    devices = {
        0: "巨石8口设备",
        1: "巨石16口设备",
        2: "巨石32口设备",
        3: "巨石48口设备",
        4: "全电4口设备",
        5: "全电10口设备",
        6: "全电10口带屏设备",
        7: "全电40口设备",
        8: "电源适配器"
    }
    if type == 0:
        return review_status[tag]

    elif type == 1:
        return delivery_status[tag]

    elif type == 2:
        return return_type[tag]

    elif type == 3:
        return bs[tag]

    elif type == 4:
        return devices[tag]

    else:
        return


def getDevices(info):
    device_obj = ReturnDevice.objects.filter(return_from=info).all()
    devices = []
    for device in device_obj:
        devices.append({"device": getTag(device.device, 4), "count": device.count})
    return devices
